package  
{
	import org.flixel.*;
	/**
	 * ...
	 * @author morgan
	 */
	public class Obstacle extends FlxObject
	{
		public var foregroundSprite:FlxSprite;
		public var backgroundSprite:FlxSprite;
		public var collisionSprite:FlxSprite;
		
		public function Obstacle() 
		{
			foregroundSprite = new FlxSprite(0, 0);
			backgroundSprite = new FlxSprite(0, 0);
			collisionSprite = new FlxSprite(0, 0);
			exists = false;
		}
		
		public function spawn(fg:Class, bg:Class, col:Class, x:int, y:int) : void
		{
			foregroundSprite.loadGraphic(fg);
			backgroundSprite.loadGraphic(bg);
			collisionSprite.loadGraphic(col);
			collisionSprite.alpha = 0.2;
			width = Math.max(foregroundSprite.width, backgroundSprite.width, collisionSprite.width);
			exists = true;
			this.x = x;
			this.y = y;
		}
		
		override public function update():void 
		{
			super.update();
			foregroundSprite.x = x;
			foregroundSprite.y = y;
			backgroundSprite.x = x;
			backgroundSprite.y = y;
			collisionSprite.x = x
			collisionSprite.y = y;
			
			
			var state:PlayState = (FlxG.state as PlayState);
			var leftScreenEdge:Number = Math.min(state.topCamera.scroll.x, state.bottomCamera.scroll.x);
			if (x + width <= leftScreenEdge)
			{
				FlxG.log("kill");
				kill();
			}
		}
	}

}